package com.timi_licai.timi_licai_account.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.timi_licai.timi_licai_account.R;
import com.timi_licai.timi_licai_account.model.AccountBook;
import com.timi_licai.timi_licai_account.model.SampleModel;

import java.util.List;

/**
 * Created by licheng  on 2015/3/13.
 * email 635408136@qq.com
 */
public class BookBaseAdapter extends BaseAdapter {
    private Context context;
    private List<AccountBook> data;

    public BookBaseAdapter(Context context, List<AccountBook> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (data != null) {
            return data.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        Object ret = null;
        if (data != null) {
            return data.get(position);
        }
        return ret;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_main_slidingmenu_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.bookName = (TextView) view.findViewById(R.id.book_name);
            viewHolder.bookCount = (TextView) view.findViewById(R.id.book_count);
            viewHolder.bookBg = (ImageView) view.findViewById(R.id.book_bg);
            viewHolder.plusText = (TextView) view.findViewById(R.id.plus_txt);
            viewHolder.bookSelectedFlag = (ImageView) view.findViewById(R.id.book_selected_flag);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();

        }
        AccountBook accountBook = data.get(position);
        if (accountBook.getId() == -1) {
            viewHolder.bookName.setText("");
            viewHolder.bookCount.setVisibility(View.GONE);
            viewHolder.bookSelectedFlag.setVisibility(View.GONE);
            viewHolder.plusText.setVisibility(View.VISIBLE);
            viewHolder.bookBg.setImageResource(R.drawable.book_bg_4);
        } else {
            if (accountBook.getIsmark() == 1) {
                viewHolder.bookCount.setVisibility(View.VISIBLE);
                viewHolder.plusText.setVisibility(View.GONE);
                viewHolder.bookSelectedFlag.setVisibility(View.VISIBLE);
                viewHolder.bookCount.setText("共计" + accountBook.getBookcount() + "笔");
                viewHolder.bookName.setText(accountBook.getBookname());
                viewHolder.bookName.setText(accountBook.getBookname());
                viewHolder.bookBg.setImageResource(R.drawable.book_bg_4);
            } else {
                viewHolder.plusText.setVisibility(View.GONE);
                viewHolder.bookSelectedFlag.setVisibility(View.GONE);
                viewHolder.bookCount.setText("共计" + accountBook.getBookcount() + "笔");
                viewHolder.bookName.setText(accountBook.getBookname());
                viewHolder.bookName.setText(accountBook.getBookname());
            }
        }
        return view;
    }

    private static class ViewHolder {
        public TextView bookName;
        public TextView bookCount;
        public ImageView bookBg;
        public TextView plusText;
        public ImageView bookSelectedFlag;

    }
}
